package lang;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class FileDemo {
	public static void main(String[] args) throws IOException {
		File file = new File("D://1.txt");
		RandomAccessFile rFile = new RandomAccessFile(file, "rw");
		/*while (true) {
			rFile.writeUTF(String.valueOf(random.nextInt(100)));
		}
		*/
		for(int i=(int) (rFile.length()-1);i>=0;i--) {
			System.out.println(rFile.readUTF());
		}
		rFile.close();
	}

	@SuppressWarnings("unused")
	private static void M1() throws IOException {
		int data_arr[] = { 12, 32, 43, 45, 1, 5 };
		try {
			RandomAccessFile file = new RandomAccessFile("temp.dat", "rw");
			for (int i = 0; i < data_arr.length; i++) {
				file.writeInt(data_arr[i]);
			}
			for (int i = data_arr.length - 1; i >= 0; i--) {
				file.seek(i * 4);
				System.out.println(file.readInt());
			}
			file.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
